package com.librariy.util;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
public class AppPackage{
    private static PackageInfo mPackageInfo;
    public static void init(Context mContext) {
        try {
            AppPackage.mPackageInfo=mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), PackageManager.GET_META_DATA);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static long versionCode(Context mContext) {
        AppPackage.init(mContext);
        return mPackageInfo==null?0:mPackageInfo.versionCode;
    }
    public static String versionName(Context mContext) {
        AppPackage.init(mContext);
        return mPackageInfo==null?"":mPackageInfo.versionName;
    }
    public static String packageName(Context mContext) {
        AppPackage.init(mContext);
        return mPackageInfo==null?"":mPackageInfo.packageName;
    }
    public static ApplicationInfo applicationInfo(Context mContext) {
        AppPackage.init(mContext);
        return mPackageInfo==null?null:mPackageInfo.applicationInfo;
    }
}
